package com.csii.modules.online.cgform.util;

import com.csii.autopoi.poi.handler.impl.ExcelDataHandlerDefaultImpl;
import com.csii.autopoi.poi.util.PoiPublicUtil;
import com.csii.core.util.SpringContextUtils;
import com.csii.modules.online.cgform.entity.OnlCgformField;
import com.csii.modules.system.service.ISysBaseAPI;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * 数据处理默认实现工具类
 *
 * 原来是 a
 */
public class ExcelDataHandlerDefaultUtil extends ExcelDataHandlerDefaultImpl {
	Map<String, OnlCgformField> map;
	ISysBaseAPI iSysBaseAPI;
	String c;
	String d;
	String e;

	public ExcelDataHandlerDefaultUtil(List<OnlCgformField> list, String var2, String var3) {
		this.map = this.createMap(list);
		this.c = var2;
		this.d = "online";
		this.e = var3;
		this.iSysBaseAPI = (ISysBaseAPI) SpringContextUtils.getBean(ISysBaseAPI.class);
	}

	private Map<String, OnlCgformField> createMap(List<OnlCgformField> list) {
		HashMap fieldMap = new HashMap();
		Iterator iterator = list.iterator();

		while (iterator.hasNext()) {
			OnlCgformField one = (OnlCgformField) iterator.next();
			fieldMap.put(one.getDbFieldTxt(), one);
		}

		return fieldMap;
	}

	public void setMapValue(Map<String, Object> map, String originKey, Object value) {
		String key = this.getToString(originKey);
		//
		if (value instanceof Double) {
			map.put(key, PoiPublicUtil.doubleToString((Double) value));
		} else if (value instanceof byte[]) {
			byte[] bytes = (byte[]) ((byte[]) value);
			String var6 = CgformSqlUtil.uploadOnlineImage(bytes, this.c, this.d, this.e);
			if (var6 != null) {
				map.put(key, var6);
			}
		} else {
			map.put(key, value == null ? "" : value.toString());
		}

	}

	private String getToString(String var1) {
		return this.map.containsKey(var1) ? "$mainTable$" + ((OnlCgformField) this.map.get(var1)).getDbFieldName() : "$subTable$" + var1;
	}
}
